package org.xtext.example.cr.generator;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.xtext.generator.IFileSystemAccess;
import org.eclipse.xtext.generator.IGenerator;
import org.eclipse.xtext.xbase.lib.BooleanExtensions;
import org.eclipse.xtext.xbase.lib.ComparableExtensions;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.StringExtensions;
import org.eclipse.xtext.xtend2.lib.StringConcatenation;
import org.xtext.example.cr.cR.Add;
import org.xtext.example.cr.cR.Archive;
import org.xtext.example.cr.cR.Array;
import org.xtext.example.cr.cR.ArrayDec;
import org.xtext.example.cr.cR.ArrayElement;
import org.xtext.example.cr.cR.ArrayMethod;
import org.xtext.example.cr.cR.Assignment;
import org.xtext.example.cr.cR.CRLanguage;
import org.xtext.example.cr.cR.CalcCR;
import org.xtext.example.cr.cR.CalcMean;
import org.xtext.example.cr.cR.Delete;
import org.xtext.example.cr.cR.Element;
import org.xtext.example.cr.cR.Folder;
import org.xtext.example.cr.cR.Function;
import org.xtext.example.cr.cR.Index;
import org.xtext.example.cr.cR.IntDec;
import org.xtext.example.cr.cR.LinuxFolder;
import org.xtext.example.cr.cR.PartitionDec;
import org.xtext.example.cr.cR.PrimitiveDec;
import org.xtext.example.cr.cR.RealDec;
import org.xtext.example.cr.cR.SimpleVariable;
import org.xtext.example.cr.cR.Size;
import org.xtext.example.cr.cR.VarDec;
import org.xtext.example.cr.cR.Variable;
import org.xtext.example.cr.cR.WindowsFolder;

@SuppressWarnings("all")
public class CRGenerator implements IGenerator {
  public void doGenerate(final Resource resource, final IFileSystemAccess fsa) {
    String _className = this.className(resource);
    String _operator_plus = StringExtensions.operator_plus(_className, ".java");
    EList<EObject> _contents = resource.getContents();
    EObject _head = IterableExtensions.<EObject>head(_contents);
    String _className_1 = this.className(resource);
    StringConcatenation _javaCode = this.toJavaCode(((CRLanguage) _head), _className_1);
    fsa.generateFile(_operator_plus, _javaCode);
  }
  
  public String className(final Resource res) {
    String _xblockexpression = null;
    {
      URI _uRI = res.getURI();
      String _lastSegment = _uRI.lastSegment();
      String name = _lastSegment;
      int _indexOf = name.indexOf(".");
      String _substring = name.substring(0, _indexOf);
      _xblockexpression = (_substring);
    }
    return _xblockexpression;
  }
  
  public StringConcatenation toJavaCode(final CRLanguage cr, final String name) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("import java.io.*;");
    _builder.newLine();
    _builder.newLine();
    _builder.append("public static void main(String[] args) {");
    _builder.newLine();
    {
      EList<Element> _elements = cr.getElements();
      boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_elements, null);
      if (_operator_notEquals) {
        {
          EList<Element> _elements_1 = cr.getElements();
          for(final Element x : _elements_1) {
            StringConcatenation _element = this.element(x);
            String _string = _element.toString();
            String _replaceAll = _string.replaceAll("\r\n", "");
            String _replaceAll_1 = _replaceAll.replaceAll(";", ";\n");
            String _replaceAll_2 = _replaceAll_1.replaceAll("{", "{\n");
            String _replaceAll_3 = _replaceAll_2.replaceAll("}", "}\n");
            _builder.append(_replaceAll_3, "");
            _builder.newLineIfNotEmpty();
          }
        }
        _builder.newLine();
        _builder.append("int size(int[] array) {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("int count = 0;");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("for (int i=0;i<array.length;i++) {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("if (array[i] != null) {");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("count++;");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("} ");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("return count;");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        _builder.newLine();
        _builder.append("int size(float[] array) {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("int count = 0;");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("for (int i=0;i<array.length;i++) {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("if (array[i] != null) {");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("count++;");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("} ");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("return count;");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        _builder.newLine();
        _builder.append("int size(Partition[] array) {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("int count = 0;");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("for (int i=0;i<array.length;i++) {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("if (array[i] != null) {");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("count++;");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("} ");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("return count;");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        _builder.newLine();
        _builder.append("int size(int[][] array) {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("int count = 0;");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("for (int i=0;i<array.length;i++) {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("for (int j=0;j<array[i].length;j++) {");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("if (array[i][j] != null) {");
        _builder.newLine();
        _builder.append("\t\t\t\t");
        _builder.append("count++;");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("} ");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("return count;");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        _builder.newLine();
        _builder.append("int size(float[][] array) {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("int count = 0;");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("for (int i=0;i<array.length;i++) {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("for (int j=0;j<array[i].length;j++) {");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("if (array[i][j] != null) {");
        _builder.newLine();
        _builder.append("\t\t\t\t");
        _builder.append("count++;");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("} ");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("return count;");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        _builder.newLine();
        _builder.append("int size(Partition[][] array) {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("int count = 0;");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("for (int i=0;i<array.length;i++) {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("for (int j=0;j<array[i].length;j++) {");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("if (array[i][j] != null) {");
        _builder.newLine();
        _builder.append("\t\t\t\t");
        _builder.append("count++;");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("} ");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("return count;");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        _builder.newLine();
        _builder.append("class Partition {");
        _builder.newLine();
        _builder.append("\t");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("private ArrayList<ArrayList<Float>> partition;");
        _builder.newLine();
        _builder.append("\t");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("Partition(String directory) {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("try {");
        _builder.newLine();
        _builder.append("\t\t\t");
        _builder.append("// Open the file that is the first command line parameter");
        _builder.newLine();
        _builder.append("\t\t  \t");
        _builder.append("FileInputStream fstream = new FileInputStream(directory);");
        _builder.newLine();
        _builder.append("\t\t  \t");
        _builder.newLine();
        _builder.append("\t\t  \t");
        _builder.append("// Get the object of DataInputStream");
        _builder.newLine();
        _builder.append("\t\t  \t");
        _builder.append("DataInputStream in = new DataInputStream(fstream);");
        _builder.newLine();
        _builder.append("\t\t  \t");
        _builder.append("BufferedReader br = new BufferedReader(new InputStreamReader(in));");
        _builder.newLine();
        _builder.append("\t\t  \t");
        _builder.newLine();
        _builder.append("\t\t  \t");
        _builder.append("// One line of the archive");
        _builder.newLine();
        _builder.append("\t\t  \t");
        _builder.append("String strLine;");
        _builder.newLine();
        _builder.append("\t\t  \t");
        _builder.newLine();
        _builder.append("\t\t  \t");
        _builder.append("//Read File Line By Line");
        _builder.newLine();
        _builder.append("\t\t  \t");
        _builder.append("while ((strLine = br.readLine()) != null)   {");
        _builder.newLine();
        _builder.append("\t\t\t  \t");
        _builder.append("// Insert data in Partition structure");
        _builder.newLine();
        _builder.append("\t\t  \t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t\t  \t");
        _builder.append("//Close the input stream");
        _builder.newLine();
        _builder.append("\t\t  \t");
        _builder.append("in.close();");
        _builder.newLine();
        _builder.append("\t    ");
        _builder.append("} catch (Exception e){//Catch exception if any");
        _builder.newLine();
        _builder.append("\t\t  \t");
        _builder.append("System.err.println(\"Error: \" + e.getMessage());");
        _builder.newLine();
        _builder.append("\t  \t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("ArrayList<ArrayList<Float>> getPartition () {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("return partition;");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("void setPartition(ArrayList<ArrayList<Float>> partition) {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("this.partition = partition;");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
      }
    }
    _builder.append("}");
    _builder.newLine();
    return _builder;
  }
  
  public StringConcatenation element(final Element e) {
    StringConcatenation _builder = new StringConcatenation();
    {
      VarDec _varDec = e.getVarDec();
      boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_varDec, null);
      if (_operator_notEquals) {
        VarDec _varDec_1 = e.getVarDec();
        StringConcatenation _varDec_2 = this.varDec(_varDec_1);
        _builder.append(_varDec_2, "");
        _builder.newLineIfNotEmpty();
      }
    }
    {
      Assignment _assignment = e.getAssignment();
      boolean _operator_notEquals_1 = ObjectExtensions.operator_notEquals(_assignment, null);
      if (_operator_notEquals_1) {
        Assignment _assignment_1 = e.getAssignment();
        StringConcatenation _assignment_2 = this.assignment(_assignment_1);
        _builder.append(_assignment_2, "");
        _builder.newLineIfNotEmpty();
      }
    }
    {
      ArrayMethod _arrayMethod = e.getArrayMethod();
      boolean _operator_notEquals_2 = ObjectExtensions.operator_notEquals(_arrayMethod, null);
      if (_operator_notEquals_2) {
        ArrayMethod _arrayMethod_1 = e.getArrayMethod();
        StringConcatenation _arrayMethod_2 = this.arrayMethod(_arrayMethod_1);
        _builder.append(_arrayMethod_2, "");
        _builder.newLineIfNotEmpty();
      }
    }
    {
      Function _function = e.getFunction();
      boolean _operator_notEquals_3 = ObjectExtensions.operator_notEquals(_function, null);
      if (_operator_notEquals_3) {
        Function _function_1 = e.getFunction();
        StringConcatenation _function_2 = this.function(_function_1);
        _builder.append(_function_2, "");
        _builder.newLineIfNotEmpty();
      }
    }
    return _builder;
  }
  
  public StringConcatenation varDec(final VarDec vd) {
    StringConcatenation _builder = new StringConcatenation();
    {
      PrimitiveDec _primitiveDec = vd.getPrimitiveDec();
      boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_primitiveDec, null);
      if (_operator_notEquals) {
        PrimitiveDec _primitiveDec_1 = vd.getPrimitiveDec();
        StringConcatenation _primitiveDec_2 = this.primitiveDec(_primitiveDec_1);
        _builder.append(_primitiveDec_2, "");
        _builder.newLineIfNotEmpty();
      }
    }
    {
      ArrayDec _arrayDec = vd.getArrayDec();
      boolean _operator_notEquals_1 = ObjectExtensions.operator_notEquals(_arrayDec, null);
      if (_operator_notEquals_1) {
        ArrayDec _arrayDec_1 = vd.getArrayDec();
        StringConcatenation _arrayDec_2 = this.arrayDec(_arrayDec_1);
        _builder.append(_arrayDec_2, "");
        _builder.newLineIfNotEmpty();
      }
    }
    return _builder;
  }
  
  public StringConcatenation primitiveDec(final PrimitiveDec pd) {
    StringConcatenation _builder = new StringConcatenation();
    {
      IntDec _intDec = pd.getIntDec();
      boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_intDec, null);
      if (_operator_notEquals) {
        IntDec _intDec_1 = pd.getIntDec();
        StringConcatenation _intDec_2 = this.intDec(_intDec_1);
        _builder.append(_intDec_2, "");
        _builder.newLineIfNotEmpty();
      }
    }
    {
      RealDec _realDec = pd.getRealDec();
      boolean _operator_notEquals_1 = ObjectExtensions.operator_notEquals(_realDec, null);
      if (_operator_notEquals_1) {
        RealDec _realDec_1 = pd.getRealDec();
        StringConcatenation _realDec_2 = this.realDec(_realDec_1);
        _builder.append(_realDec_2, "");
        _builder.newLineIfNotEmpty();
      }
    }
    {
      PartitionDec _partitionDec = pd.getPartitionDec();
      boolean _operator_notEquals_2 = ObjectExtensions.operator_notEquals(_partitionDec, null);
      if (_operator_notEquals_2) {
        PartitionDec _partitionDec_1 = pd.getPartitionDec();
        StringConcatenation _partitionDec_2 = this.partitionDec(_partitionDec_1);
        _builder.append(_partitionDec_2, "");
        _builder.newLineIfNotEmpty();
      }
    }
    return _builder;
  }
  
  public StringConcatenation intDec(final IntDec id) {
    StringConcatenation _builder = new StringConcatenation();
    {
      EList<SimpleVariable> _vars = id.getVars();
      boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_vars, null);
      if (_operator_notEquals) {
        {
          EList<SimpleVariable> _vars_1 = id.getVars();
          for(final SimpleVariable x : _vars_1) {
            _builder.append("int ");
            StringConcatenation _simpleVariable = this.simpleVariable(x);
            _builder.append(_simpleVariable, "");
            _builder.append(";");
            _builder.newLineIfNotEmpty();
          }
        }
      }
    }
    return _builder;
  }
  
  public StringConcatenation simpleVariable(final SimpleVariable sv) {
    StringConcatenation _builder = new StringConcatenation();
    {
      String _name = sv.getName();
      boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_name, null);
      if (_operator_notEquals) {
        String _name_1 = sv.getName();
        _builder.append(_name_1, "");
        _builder.newLineIfNotEmpty();
      }
    }
    return _builder;
  }
  
  public StringConcatenation realDec(final RealDec rd) {
    StringConcatenation _builder = new StringConcatenation();
    {
      EList<SimpleVariable> _vars = rd.getVars();
      boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_vars, null);
      if (_operator_notEquals) {
        {
          EList<SimpleVariable> _vars_1 = rd.getVars();
          for(final SimpleVariable x : _vars_1) {
            _builder.append("float ");
            StringConcatenation _simpleVariable = this.simpleVariable(x);
            _builder.append(_simpleVariable, "");
            _builder.append(";");
            _builder.newLineIfNotEmpty();
          }
        }
      }
    }
    return _builder;
  }
  
  public StringConcatenation partitionDec(final PartitionDec pd) {
    StringConcatenation _builder = new StringConcatenation();
    {
      EList<SimpleVariable> _vars = pd.getVars();
      boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_vars, null);
      if (_operator_notEquals) {
        {
          EList<SimpleVariable> _vars_1 = pd.getVars();
          for(final SimpleVariable x : _vars_1) {
            _builder.append("Partition ");
            StringConcatenation _simpleVariable = this.simpleVariable(x);
            _builder.append(_simpleVariable, "");
            _builder.append(";");
            _builder.newLineIfNotEmpty();
          }
        }
      }
    }
    return _builder;
  }
  
  public StringConcatenation arrayDec(final ArrayDec ad) {
    StringConcatenation _builder = new StringConcatenation();
    {
      String _type = ad.getType();
      boolean _equals = _type.equals("Int");
      if (_equals) {
        {
          int _rows = ad.getRows();
          boolean _operator_lessThan = ComparableExtensions.<Integer>operator_lessThan(((Integer)_rows), ((Integer)1));
          if (_operator_lessThan) {
            {
              EList<Array> _arrayVars = ad.getArrayVars();
              for(final Array x : _arrayVars) {
                _builder.append("int[");
                int _colums = ad.getColums();
                _builder.append(_colums, "");
                _builder.append("] ");
                StringConcatenation _array = this.array(x);
                _builder.append(_array, "");
                _builder.append(";");
                _builder.newLineIfNotEmpty();
              }
            }
          } else {
            {
              EList<Array> _arrayVars_1 = ad.getArrayVars();
              for(final Array x_1 : _arrayVars_1) {
                _builder.append("int[");
                int _colums_1 = ad.getColums();
                _builder.append(_colums_1, "");
                _builder.append("][");
                int _rows_1 = ad.getRows();
                _builder.append(_rows_1, "");
                _builder.append("] ");
                StringConcatenation _array_1 = this.array(x_1);
                _builder.append(_array_1, "");
                _builder.append(";");
                _builder.newLineIfNotEmpty();
              }
            }
          }
        }
      } else {
        String _type_1 = ad.getType();
        boolean _equals_1 = _type_1.equals("Real");
        if (_equals_1) {
          {
            int _rows_2 = ad.getRows();
            boolean _operator_lessThan_1 = ComparableExtensions.<Integer>operator_lessThan(((Integer)_rows_2), ((Integer)1));
            if (_operator_lessThan_1) {
              {
                EList<Array> _arrayVars_2 = ad.getArrayVars();
                for(final Array x_2 : _arrayVars_2) {
                  _builder.append("float[");
                  int _colums_2 = ad.getColums();
                  _builder.append(_colums_2, "");
                  _builder.append("] ");
                  StringConcatenation _array_2 = this.array(x_2);
                  _builder.append(_array_2, "");
                  _builder.append(";");
                  _builder.newLineIfNotEmpty();
                }
              }
            } else {
              {
                EList<Array> _arrayVars_3 = ad.getArrayVars();
                for(final Array x_3 : _arrayVars_3) {
                  _builder.append("float[");
                  int _colums_3 = ad.getColums();
                  _builder.append(_colums_3, "");
                  _builder.append("][");
                  int _rows_3 = ad.getRows();
                  _builder.append(_rows_3, "");
                  _builder.append("] ");
                  StringConcatenation _array_3 = this.array(x_3);
                  _builder.append(_array_3, "");
                  _builder.append(";");
                  _builder.newLineIfNotEmpty();
                }
              }
            }
          }
        } else {
          {
            int _rows_4 = ad.getRows();
            boolean _operator_lessThan_2 = ComparableExtensions.<Integer>operator_lessThan(((Integer)_rows_4), ((Integer)1));
            if (_operator_lessThan_2) {
              {
                EList<Array> _arrayVars_4 = ad.getArrayVars();
                for(final Array x_4 : _arrayVars_4) {
                  _builder.append("Partition[");
                  int _colums_4 = ad.getColums();
                  _builder.append(_colums_4, "");
                  _builder.append("] ");
                  StringConcatenation _array_4 = this.array(x_4);
                  _builder.append(_array_4, "");
                  _builder.append(";");
                  _builder.newLineIfNotEmpty();
                }
              }
            } else {
              {
                EList<Array> _arrayVars_5 = ad.getArrayVars();
                for(final Array x_5 : _arrayVars_5) {
                  _builder.append("Partition[");
                  int _colums_5 = ad.getColums();
                  _builder.append(_colums_5, "");
                  _builder.append("][");
                  int _rows_5 = ad.getRows();
                  _builder.append(_rows_5, "");
                  _builder.append("] ");
                  StringConcatenation _array_5 = this.array(x_5);
                  _builder.append(_array_5, "");
                  _builder.append(";");
                  _builder.newLineIfNotEmpty();
                }
              }
            }
          }
        }
      }
    }
    return _builder;
  }
  
  public StringConcatenation array(final Array a) {
    StringConcatenation _builder = new StringConcatenation();
    {
      String _name = a.getName();
      boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_name, null);
      if (_operator_notEquals) {
        String _name_1 = a.getName();
        _builder.append(_name_1, "");
        _builder.newLineIfNotEmpty();
      }
    }
    return _builder;
  }
  
  public StringConcatenation assignment(final Assignment a) {
    StringConcatenation _builder = new StringConcatenation();
    {
      VarDec _dec = a.getDec();
      boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_dec, null);
      if (_operator_notEquals) {
        VarDec _dec_1 = a.getDec();
        StringConcatenation _varDec = this.varDec(_dec_1);
        _builder.append(_varDec, "");
        _builder.newLineIfNotEmpty();
        {
          VarDec _dec_2 = a.getDec();
          PrimitiveDec _primitiveDec = _dec_2.getPrimitiveDec();
          boolean _operator_notEquals_1 = ObjectExtensions.operator_notEquals(_primitiveDec, null);
          if (_operator_notEquals_1) {
            {
              VarDec _dec_3 = a.getDec();
              PrimitiveDec _primitiveDec_1 = _dec_3.getPrimitiveDec();
              IntDec _intDec = _primitiveDec_1.getIntDec();
              boolean _operator_notEquals_2 = ObjectExtensions.operator_notEquals(_intDec, null);
              if (_operator_notEquals_2) {
                {
                  VarDec _dec_4 = a.getDec();
                  PrimitiveDec _primitiveDec_2 = _dec_4.getPrimitiveDec();
                  IntDec _intDec_1 = _primitiveDec_2.getIntDec();
                  EList<SimpleVariable> _vars = _intDec_1.getVars();
                  for(final SimpleVariable x : _vars) {
                    StringConcatenation _simpleVariable = this.simpleVariable(x);
                    _builder.append(_simpleVariable, "");
                    _builder.append(" = ");
                    _builder.newLineIfNotEmpty();
                  }
                }
              } else {
                VarDec _dec_5 = a.getDec();
                PrimitiveDec _primitiveDec_3 = _dec_5.getPrimitiveDec();
                RealDec _realDec = _primitiveDec_3.getRealDec();
                boolean _operator_notEquals_3 = ObjectExtensions.operator_notEquals(_realDec, null);
                if (_operator_notEquals_3) {
                  {
                    VarDec _dec_6 = a.getDec();
                    PrimitiveDec _primitiveDec_4 = _dec_6.getPrimitiveDec();
                    RealDec _realDec_1 = _primitiveDec_4.getRealDec();
                    EList<SimpleVariable> _vars_1 = _realDec_1.getVars();
                    for(final SimpleVariable x_1 : _vars_1) {
                      StringConcatenation _simpleVariable_1 = this.simpleVariable(x_1);
                      _builder.append(_simpleVariable_1, "");
                      _builder.append(" = ");
                      _builder.newLineIfNotEmpty();
                    }
                  }
                } else {
                  VarDec _dec_7 = a.getDec();
                  PrimitiveDec _primitiveDec_5 = _dec_7.getPrimitiveDec();
                  PartitionDec _partitionDec = _primitiveDec_5.getPartitionDec();
                  boolean _operator_notEquals_4 = ObjectExtensions.operator_notEquals(_partitionDec, null);
                  if (_operator_notEquals_4) {
                    {
                      VarDec _dec_8 = a.getDec();
                      PrimitiveDec _primitiveDec_6 = _dec_8.getPrimitiveDec();
                      PartitionDec _partitionDec_1 = _primitiveDec_6.getPartitionDec();
                      EList<SimpleVariable> _vars_2 = _partitionDec_1.getVars();
                      for(final SimpleVariable x_2 : _vars_2) {
                        StringConcatenation _simpleVariable_2 = this.simpleVariable(x_2);
                        _builder.append(_simpleVariable_2, "");
                        _builder.append(" = ");
                        _builder.newLineIfNotEmpty();
                      }
                    }
                  }
                }
              }
            }
          } else {
            VarDec _dec_9 = a.getDec();
            ArrayDec _arrayDec = _dec_9.getArrayDec();
            boolean _operator_notEquals_5 = ObjectExtensions.operator_notEquals(_arrayDec, null);
            if (_operator_notEquals_5) {
              {
                VarDec _dec_10 = a.getDec();
                ArrayDec _arrayDec_1 = _dec_10.getArrayDec();
                EList<Array> _arrayVars = _arrayDec_1.getArrayVars();
                for(final Array x_3 : _arrayVars) {
                  StringConcatenation _array = this.array(x_3);
                  _builder.append(_array, "");
                  _builder.append(" = ");
                  _builder.newLineIfNotEmpty();
                }
              }
            }
          }
        }
      } else {
        EList<Variable> _variables = a.getVariables();
        boolean _operator_notEquals_6 = ObjectExtensions.operator_notEquals(_variables, null);
        if (_operator_notEquals_6) {
          {
            EList<Variable> _variables_1 = a.getVariables();
            for(final Variable x_4 : _variables_1) {
              StringConcatenation _variable = this.variable(x_4);
              _builder.append(_variable, "");
              _builder.append(" = ");
              _builder.newLineIfNotEmpty();
            }
          }
        } else {
          ArrayElement _arrayElement = a.getArrayElement();
          boolean _operator_notEquals_7 = ObjectExtensions.operator_notEquals(_arrayElement, null);
          if (_operator_notEquals_7) {
            ArrayElement _arrayElement_1 = a.getArrayElement();
            StringConcatenation _arrayElement_2 = this.arrayElement(_arrayElement_1);
            _builder.append(_arrayElement_2, "");
            _builder.append(" = ");
            _builder.newLineIfNotEmpty();
          }
        }
      }
    }
    _builder.newLine();
    {
      CalcCR _calcCR = a.getCalcCR();
      boolean _operator_notEquals_8 = ObjectExtensions.operator_notEquals(_calcCR, null);
      if (_operator_notEquals_8) {
        CalcCR _calcCR_1 = a.getCalcCR();
        StringConcatenation _calcCR_2 = this.calcCR(_calcCR_1);
        _builder.append(_calcCR_2, "");
        _builder.append(";");
        _builder.newLineIfNotEmpty();
      } else {
        CalcMean _calcMean = a.getCalcMean();
        boolean _operator_notEquals_9 = ObjectExtensions.operator_notEquals(_calcMean, null);
        if (_operator_notEquals_9) {
          CalcMean _calcMean_1 = a.getCalcMean();
          StringConcatenation _calcMean_2 = this.calcMean(_calcMean_1);
          _builder.append(_calcMean_2, "");
          _builder.append(";");
          _builder.newLineIfNotEmpty();
        } else {
          org.xtext.example.cr.cR.Number _number = a.getNumber();
          boolean _operator_notEquals_10 = ObjectExtensions.operator_notEquals(_number, null);
          if (_operator_notEquals_10) {
            org.xtext.example.cr.cR.Number _number_1 = a.getNumber();
            StringConcatenation _number_2 = this.number(_number_1);
            _builder.append(_number_2, "");
            _builder.append(";");
            _builder.newLineIfNotEmpty();
          } else {
            Archive _archive = a.getArchive();
            boolean _operator_notEquals_11 = ObjectExtensions.operator_notEquals(_archive, null);
            if (_operator_notEquals_11) {
              Archive _archive_1 = a.getArchive();
              StringConcatenation _archive_2 = this.archive(_archive_1);
              String _string = _archive_2.toString();
              String _trim = _string.trim();
              _builder.append(_trim, "");
              _builder.append(";");
              _builder.newLineIfNotEmpty();
            } else {
              Variable _variable_1 = a.getVariable();
              boolean _operator_notEquals_12 = ObjectExtensions.operator_notEquals(_variable_1, null);
              if (_operator_notEquals_12) {
                Variable _variable_2 = a.getVariable();
                StringConcatenation _variable_3 = this.variable(_variable_2);
                _builder.append(_variable_3, "");
                _builder.append(";");
                _builder.newLineIfNotEmpty();
              } else {
                ArrayElement _assignedAE = a.getAssignedAE();
                boolean _operator_notEquals_13 = ObjectExtensions.operator_notEquals(_assignedAE, null);
                if (_operator_notEquals_13) {
                  ArrayElement _assignedAE_1 = a.getAssignedAE();
                  StringConcatenation _arrayElement_3 = this.arrayElement(_assignedAE_1);
                  _builder.append(_arrayElement_3, "");
                  _builder.append(";");
                  _builder.newLineIfNotEmpty();
                }
              }
            }
          }
        }
      }
    }
    return _builder;
  }
  
  public StringConcatenation variable(final Variable v) {
    StringConcatenation _builder = new StringConcatenation();
    {
      String _name = v.getName();
      boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_name, null);
      if (_operator_notEquals) {
        String _name_1 = v.getName();
        _builder.append(_name_1, "");
        _builder.newLineIfNotEmpty();
      }
    }
    return _builder;
  }
  
  public StringConcatenation number(final org.xtext.example.cr.cR.Number n) {
    StringConcatenation _builder = new StringConcatenation();
    {
      int _integer = n.getInteger();
      boolean _operator_notEquals = ObjectExtensions.operator_notEquals(((Integer)_integer), null);
      if (_operator_notEquals) {
        {
          int _decimal = n.getDecimal();
          boolean _operator_greaterThan = ComparableExtensions.<Integer>operator_greaterThan(((Integer)_decimal), ((Integer)0));
          if (_operator_greaterThan) {
            int _integer_1 = n.getInteger();
            _builder.append(_integer_1, "");
            _builder.append(",");
            int _decimal_1 = n.getDecimal();
            _builder.append(_decimal_1, "");
            _builder.newLineIfNotEmpty();
          } else {
            int _integer_2 = n.getInteger();
            _builder.append(_integer_2, "");
            _builder.newLineIfNotEmpty();
          }
        }
      }
    }
    return _builder;
  }
  
  public StringConcatenation archive(final Archive a) {
    StringConcatenation _builder = new StringConcatenation();
    {
      Folder _folder = a.getFolder();
      boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_folder, null);
      if (_operator_notEquals) {
        {
          Folder _folder_1 = a.getFolder();
          LinuxFolder _linuxFolder = _folder_1.getLinuxFolder();
          boolean _operator_notEquals_1 = ObjectExtensions.operator_notEquals(_linuxFolder, null);
          if (_operator_notEquals_1) {
            {
              Folder _folder_2 = a.getFolder();
              LinuxFolder _linuxFolder_1 = _folder_2.getLinuxFolder();
              EList<String> _unixFolder = _linuxFolder_1.getUnixFolder();
              for(final String x : _unixFolder) {
                _builder.append(x, "");
                _builder.newLineIfNotEmpty();
              }
            }
          } else {
            Folder _folder_3 = a.getFolder();
            WindowsFolder _windowsFolder = _folder_3.getWindowsFolder();
            boolean _operator_notEquals_2 = ObjectExtensions.operator_notEquals(_windowsFolder, null);
            if (_operator_notEquals_2) {
              {
                Folder _folder_4 = a.getFolder();
                WindowsFolder _windowsFolder_1 = _folder_4.getWindowsFolder();
                EList<String> _windowsFolder_2 = _windowsFolder_1.getWindowsFolder();
                for(final String x_1 : _windowsFolder_2) {
                  _builder.append(x_1, "");
                  _builder.newLineIfNotEmpty();
                }
              }
            }
          }
        }
      }
    }
    {
      EList<String> _arq = a.getArq();
      for(final String x_2 : _arq) {
        _builder.append(x_2, "");
        _builder.newLineIfNotEmpty();
      }
    }
    return _builder;
  }
  
  public StringConcatenation arrayElement(final ArrayElement ae) {
    StringConcatenation _builder = new StringConcatenation();
    {
      Array _array = ae.getArray();
      boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_array, null);
      if (_operator_notEquals) {
        {
          boolean _operator_and = false;
          Index _idx = ae.getIdx();
          int _param2 = _idx.getParam2();
          boolean _operator_lessThan = ComparableExtensions.<Integer>operator_lessThan(((Integer)_param2), ((Integer)1));
          if (!_operator_lessThan) {
            _operator_and = false;
          } else {
            Index _idx_1 = ae.getIdx();
            SimpleVariable _var2 = _idx_1.getVar2();
            boolean _operator_equals = ObjectExtensions.operator_equals(_var2, null);
            _operator_and = BooleanExtensions.operator_and(_operator_lessThan, _operator_equals);
          }
          if (_operator_and) {
            {
              Index _idx_2 = ae.getIdx();
              SimpleVariable _var1 = _idx_2.getVar1();
              boolean _operator_notEquals_1 = ObjectExtensions.operator_notEquals(_var1, null);
              if (_operator_notEquals_1) {
                Array _array_1 = ae.getArray();
                String _name = _array_1.getName();
                _builder.append(_name, "");
                _builder.append("[");
                Index _idx_3 = ae.getIdx();
                SimpleVariable _var1_1 = _idx_3.getVar1();
                _builder.append(_var1_1, "");
                _builder.append("]");
                _builder.newLineIfNotEmpty();
              } else {
                Array _array_2 = ae.getArray();
                String _name_1 = _array_2.getName();
                _builder.append(_name_1, "");
                _builder.append("[");
                Index _idx_4 = ae.getIdx();
                int _param1 = _idx_4.getParam1();
                _builder.append(_param1, "");
                _builder.append("]");
                _builder.newLineIfNotEmpty();
              }
            }
          } else {
            Index _idx_5 = ae.getIdx();
            int _param2_1 = _idx_5.getParam2();
            boolean _operator_greaterThan = ComparableExtensions.<Integer>operator_greaterThan(((Integer)_param2_1), ((Integer)0));
            if (_operator_greaterThan) {
              {
                Index _idx_6 = ae.getIdx();
                SimpleVariable _var1_2 = _idx_6.getVar1();
                boolean _operator_notEquals_2 = ObjectExtensions.operator_notEquals(_var1_2, null);
                if (_operator_notEquals_2) {
                  Array _array_3 = ae.getArray();
                  String _name_2 = _array_3.getName();
                  _builder.append(_name_2, "");
                  _builder.append("[");
                  Index _idx_7 = ae.getIdx();
                  SimpleVariable _var1_3 = _idx_7.getVar1();
                  _builder.append(_var1_3, "");
                  _builder.append("][");
                  Index _idx_8 = ae.getIdx();
                  int _param2_2 = _idx_8.getParam2();
                  _builder.append(_param2_2, "");
                  _builder.append("]");
                  _builder.newLineIfNotEmpty();
                } else {
                  Array _array_4 = ae.getArray();
                  String _name_3 = _array_4.getName();
                  _builder.append(_name_3, "");
                  _builder.append("[");
                  Index _idx_9 = ae.getIdx();
                  int _param1_1 = _idx_9.getParam1();
                  _builder.append(_param1_1, "");
                  _builder.append("][");
                  Index _idx_10 = ae.getIdx();
                  int _param2_3 = _idx_10.getParam2();
                  _builder.append(_param2_3, "");
                  _builder.append("]");
                  _builder.newLineIfNotEmpty();
                }
              }
            } else {
              {
                Index _idx_11 = ae.getIdx();
                SimpleVariable _var1_4 = _idx_11.getVar1();
                boolean _operator_notEquals_3 = ObjectExtensions.operator_notEquals(_var1_4, null);
                if (_operator_notEquals_3) {
                  Array _array_5 = ae.getArray();
                  String _name_4 = _array_5.getName();
                  _builder.append(_name_4, "");
                  _builder.append("[");
                  Index _idx_12 = ae.getIdx();
                  SimpleVariable _var1_5 = _idx_12.getVar1();
                  _builder.append(_var1_5, "");
                  _builder.append("][");
                  Index _idx_13 = ae.getIdx();
                  SimpleVariable _var2_1 = _idx_13.getVar2();
                  _builder.append(_var2_1, "");
                  _builder.append("]");
                  _builder.newLineIfNotEmpty();
                } else {
                  Array _array_6 = ae.getArray();
                  String _name_5 = _array_6.getName();
                  _builder.append(_name_5, "");
                  _builder.append("[");
                  Index _idx_14 = ae.getIdx();
                  int _param1_2 = _idx_14.getParam1();
                  _builder.append(_param1_2, "");
                  _builder.append("][");
                  Index _idx_15 = ae.getIdx();
                  SimpleVariable _var2_2 = _idx_15.getVar2();
                  _builder.append(_var2_2, "");
                  _builder.append("]");
                  _builder.newLineIfNotEmpty();
                }
              }
            }
          }
        }
      }
    }
    return _builder;
  }
  
  public StringConcatenation calcCR(final CalcCR c) {
    StringConcatenation _builder = new StringConcatenation();
    {
      Array _vector = c.getVector();
      boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_vector, null);
      if (_operator_notEquals) {
        _builder.append("calcCR(");
        Array _vector_1 = c.getVector();
        StringConcatenation _array = this.array(_vector_1);
        _builder.append(_array, "");
        _builder.append(")");
        _builder.newLineIfNotEmpty();
      } else {
        ArrayElement _arrayElement = c.getArrayElement();
        boolean _operator_notEquals_1 = ObjectExtensions.operator_notEquals(_arrayElement, null);
        if (_operator_notEquals_1) {
          _builder.append("calcCR(");
          ArrayElement _arrayElement_1 = c.getArrayElement();
          StringConcatenation _arrayElement_2 = this.arrayElement(_arrayElement_1);
          _builder.append(_arrayElement_2, "");
          _builder.append(")");
          _builder.newLineIfNotEmpty();
        } else {
          ArrayElement _arrayElement1 = c.getArrayElement1();
          boolean _operator_notEquals_2 = ObjectExtensions.operator_notEquals(_arrayElement1, null);
          if (_operator_notEquals_2) {
            {
              ArrayElement _arrayElement2 = c.getArrayElement2();
              boolean _operator_notEquals_3 = ObjectExtensions.operator_notEquals(_arrayElement2, null);
              if (_operator_notEquals_3) {
                _builder.append("calcCR(");
                ArrayElement _arrayElement1_1 = c.getArrayElement1();
                StringConcatenation _arrayElement_3 = this.arrayElement(_arrayElement1_1);
                _builder.append(_arrayElement_3, "");
                _builder.append(", ");
                ArrayElement _arrayElement2_1 = c.getArrayElement2();
                StringConcatenation _arrayElement_4 = this.arrayElement(_arrayElement2_1);
                _builder.append(_arrayElement_4, "");
                _builder.append(")");
                _builder.newLineIfNotEmpty();
              } else {
                Variable _var2 = c.getVar2();
                boolean _operator_notEquals_4 = ObjectExtensions.operator_notEquals(_var2, null);
                if (_operator_notEquals_4) {
                  _builder.append("calcCR(");
                  ArrayElement _arrayElement1_2 = c.getArrayElement1();
                  StringConcatenation _arrayElement_5 = this.arrayElement(_arrayElement1_2);
                  _builder.append(_arrayElement_5, "");
                  _builder.append(", ");
                  Variable _var2_1 = c.getVar2();
                  StringConcatenation _variable = this.variable(_var2_1);
                  _builder.append(_variable, "");
                  _builder.append(")");
                  _builder.newLineIfNotEmpty();
                }
              }
            }
          } else {
            SimpleVariable _var1 = c.getVar1();
            boolean _operator_notEquals_5 = ObjectExtensions.operator_notEquals(_var1, null);
            if (_operator_notEquals_5) {
              {
                ArrayElement _arrayElement2_2 = c.getArrayElement2();
                boolean _operator_notEquals_6 = ObjectExtensions.operator_notEquals(_arrayElement2_2, null);
                if (_operator_notEquals_6) {
                  _builder.append("calcCR(");
                  SimpleVariable _var1_1 = c.getVar1();
                  StringConcatenation _simpleVariable = this.simpleVariable(_var1_1);
                  _builder.append(_simpleVariable, "");
                  _builder.append(", ");
                  ArrayElement _arrayElement2_3 = c.getArrayElement2();
                  StringConcatenation _arrayElement_6 = this.arrayElement(_arrayElement2_3);
                  _builder.append(_arrayElement_6, "");
                  _builder.append(")");
                  _builder.newLineIfNotEmpty();
                } else {
                  Variable _var2_2 = c.getVar2();
                  boolean _operator_notEquals_7 = ObjectExtensions.operator_notEquals(_var2_2, null);
                  if (_operator_notEquals_7) {
                    _builder.append("calcCR(");
                    SimpleVariable _var1_2 = c.getVar1();
                    StringConcatenation _simpleVariable_1 = this.simpleVariable(_var1_2);
                    _builder.append(_simpleVariable_1, "");
                    _builder.append(", ");
                    Variable _var2_3 = c.getVar2();
                    StringConcatenation _variable_1 = this.variable(_var2_3);
                    _builder.append(_variable_1, "");
                    _builder.append(")");
                    _builder.newLineIfNotEmpty();
                  }
                }
              }
            }
          }
        }
      }
    }
    return _builder;
  }
  
  public StringConcatenation calcMean(final CalcMean c) {
    StringConcatenation _builder = new StringConcatenation();
    {
      Array _array = c.getArray();
      boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_array, null);
      if (_operator_notEquals) {
        _builder.append("calcMean(");
        Array _array_1 = c.getArray();
        StringConcatenation _array_2 = this.array(_array_1);
        _builder.append(_array_2, "");
        _builder.append(")");
        _builder.newLineIfNotEmpty();
      } else {
        ArrayElement _arrayElement = c.getArrayElement();
        boolean _operator_notEquals_1 = ObjectExtensions.operator_notEquals(_arrayElement, null);
        if (_operator_notEquals_1) {
          _builder.append("calcMean(");
          ArrayElement _arrayElement_1 = c.getArrayElement();
          StringConcatenation _arrayElement_2 = this.arrayElement(_arrayElement_1);
          _builder.append(_arrayElement_2, "");
          _builder.append(")");
          _builder.newLineIfNotEmpty();
        } else {
          CalcCR _calcCR = c.getCalcCR();
          boolean _operator_notEquals_2 = ObjectExtensions.operator_notEquals(_calcCR, null);
          if (_operator_notEquals_2) {
            _builder.append("calcMean(");
            CalcCR _calcCR_1 = c.getCalcCR();
            StringConcatenation _calcCR_2 = this.calcCR(_calcCR_1);
            _builder.append(_calcCR_2, "");
            _builder.append(")");
            _builder.newLineIfNotEmpty();
          }
        }
      }
    }
    return _builder;
  }
  
  public StringConcatenation arrayMethod(final ArrayMethod am) {
    StringConcatenation _builder = new StringConcatenation();
    {
      Size _size = am.getSize();
      boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_size, null);
      if (_operator_notEquals) {
        _builder.append("\t");
        _builder.newLine();
      } else {
        Add _add = am.getAdd();
        boolean _operator_notEquals_1 = ObjectExtensions.operator_notEquals(_add, null);
        if (_operator_notEquals_1) {
          _builder.append("\t");
          _builder.newLine();
        } else {
          Delete _delete = am.getDelete();
          boolean _operator_notEquals_2 = ObjectExtensions.operator_notEquals(_delete, null);
          if (_operator_notEquals_2) {
            _builder.append("\t");
            _builder.newLine();
          }
        }
      }
    }
    return _builder;
  }
  
  public StringConcatenation function(final Function f) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("\t");
    _builder.newLine();
    return _builder;
  }
}
